Program the Internet of Things with Swift for iOS by Ahmed Bakir Gheorghe Chesler & Manny Torriente

Program the Internet of Things with Swift for iOS by Ahmed Bakir Gheorghe Chesler & Manny Torriente

Author:Ahmed Bakir, Gheorghe Chesler & Manny Torriente
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


As shown in Figure 8-4, add a label in your storyboard scene, after the time label. Be sure to connect the property via the Connection Inspector in Interface Builder.

Figure 8-4.Adding a label to the storyboard

To perform the weather look-up, you need to provide Weather Underground with a zip code. In the awakeWithContext() method of the class, add a geocoder to convert the location to a place-mark with human-readable attributes (Listing 8-22).

Listing 8-22.Performing a Weather Look-up (LocationInterfaceController.swift)

override func awakeWithContext(context: AnyObject?) {

super.awakeWithContext(context)

// Configure interface objects here.

// Configure interface objects here.

if let locationDict = context as? Dictionary<String, AnyObject> {

if let latitude = locationDict["Latitude"] as? Double {

if let longitude = locationDict["Longitude"] as? Double {

let location = CLLocation(latitude: latitude, longitude: longitude)

let prettyLocation = String(format: "%.2f, %.2f", location.coordinate.latitude, location.coordinate.longitude)

coordinatesLabel?.setText(prettyLocation)

currentLocation = CLLocation(latitude: latitude, longitude: longitude)

locationMap?.addAnnotation(location.coordinate, withPinColor: WKInterfaceMapPinColor.Red)

let mapRegion = MKCoordinateRegionMake(location.coordinate, MKCoordinateSpanMake(0.1, 0.1))

locationMap?.setRegion(mapRegion)

geocodeLocation()

}

}

if let timestamp = locationDict["Timestamp"] as? NSDate {

...

}

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.